package me.xiaosiqi.syt.hosp.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.xiaosiqi.syt.common.result.Result;
import me.xiaosiqi.syt.hosp.service.DepartmentService;
import me.xiaosiqi.syt.hosp.service.HospitalService;
import me.xiaosiqi.syt.hosp.service.HospitalSetService;
import me.xiaosiqi.syt.hosp.service.ScheduleService;
import me.xiaosiqi.syt.model.hosp.Department;
import me.xiaosiqi.syt.model.hosp.Hospital;
import me.xiaosiqi.syt.model.hosp.Schedule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

/**
 * @author: xiaosiqi
 * @date:2022/7/31 15:01
 */
@Api(tags = "医院设置开放接口")
@RestController
@RequestMapping("/api/hosp")
public class ApiController {
    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private HospitalSetService hospitalSetService;

    @Autowired
    private ScheduleService scheduleService;


    @ApiOperation("保存医院信息")
    @PostMapping("saveHospital")
    public Result saveHospital(Hospital hospital) {
        hospital.setLogoData(hospital.getLogoData().replace(" ", "+"));
        String hoscode = hospital.getHoscode();
        String sign = hospital.getSign();
        hospitalSetService.chikeSign(hoscode, sign);
        hospitalService.saveHospital(hospital);
        return Result.ok();
    }

    @ApiOperation("查询医院信息列表")
    @PostMapping("hospital/list")
    public Result hospitalList() {
        return Result.ok();
    }

    @ApiOperation("查询医院信息")
    @PostMapping("hospital/show")
    public Result hospitalShow(String hoscode, String sign) {
        hospitalSetService.chikeSign(hoscode, sign);
        Hospital getHospital = hospitalService.getByHoscode(hoscode);
        return Result.ok(getHospital);
    }


    @ApiOperation("上传科室接口")
    @PostMapping("saveDepartment")
    public Result saveDepartment(Department department) {
        String hoscode = department.getHoscode();
        String sign = department.getSign();
        hospitalSetService.chikeSign(hoscode, sign);
        departmentService.saveDepartment(department);
        return Result.ok();
    }

    @ApiOperation("查询科室接口")
    @PostMapping("department/list")
    public Result departmentList(String hoscode, String sign, Integer page, Integer limit) {
        hospitalSetService.chikeSign(hoscode, sign);
        if (null == page) {
            page = 1;
        }
        if (null == limit) {
            limit = 15;
        }
        Page<Department> departments = departmentService.departmentList(hoscode, page, limit);
        return Result.ok(departments);
    }

    @ApiOperation("删除科室接口")
    @PostMapping("department/remove")
    public Result departmentRemove(String hoscode, String sign, String depcode) {
        hospitalSetService.chikeSign(hoscode, sign);
        departmentService.departmentRemove(hoscode, depcode);
        return Result.ok();
    }

    @ApiOperation("上传科排班接口")
    @PostMapping("saveSchedule")
    public Result saveSchedule(Schedule schedule) {
        String hoscode = schedule.getHoscode();
        String sign = schedule.getSign();
        hospitalSetService.chikeSign(hoscode, sign);
        scheduleService.saveSchedule(schedule);
        return Result.ok();
    }

    @ApiOperation("查询科室接口")
    @PostMapping("schedule/list")
    public Result scheduleList(String hoscode, String sign,String hosScheduleId,Integer page, Integer limit) {
        hospitalSetService.chikeSign(hoscode, sign);
        if (null == page) {
            page = 1;
        }
        if (null == limit) {
            limit = 15;
        }
        Page<Schedule> scheduleList = scheduleService.scheduleList(hoscode,hosScheduleId ,page, limit);
        return Result.ok(scheduleList);
    }

    @ApiOperation("删除科室接口")
    @PostMapping("schedule/remove")
    public Result scheduleRemove(String hoscode, String sign, String hosScheduleId) {
        hospitalSetService.chikeSign(hoscode, sign);
        scheduleService.scheduleRemove(hoscode,hosScheduleId);
        return Result.ok();
    }

}
